﻿CREATE TABLE [dbo].[arhRulaje] (
    [CodFormula]        BIGINT          NOT NULL,
    [ContDebit]         [dbo].[TipCont] NOT NULL,
    [ContCredit]        [dbo].[TipCont] NOT NULL,
    [CodValuta]         SMALLINT        DEFAULT ((0)) NOT NULL,
    [IDDocument]        BIGINT          NOT NULL,
    [ValoareValuta]     DECIMAL (20, 2) DEFAULT ((0)) NOT NULL,
    [Curs]              DECIMAL (18, 4) DEFAULT ((1)) NOT NULL,
    [ValoareLei]        DECIMAL (20, 2) DEFAULT ((0)) NOT NULL,
    [DataDocJust]       DATETIME        NOT NULL,
    [TipDocJust]        VARCHAR (10)    DEFAULT ('NC') NOT NULL,
    [NumarDocJust]      DECIMAL (18)    NOT NULL,
    [ExplicatiiDocJust] VARCHAR (200)   NOT NULL,
    [NrCrt]             SMALLINT        DEFAULT ((1)) NOT NULL,
    [CodUnitate]        SMALLINT        DEFAULT ((0)) NOT NULL,
    [An]                SMALLINT        DEFAULT ((0)) NOT NULL,
    CONSTRAINT [PK_arhRulaje] PRIMARY KEY CLUSTERED ([CodFormula] ASC),
    CONSTRAINT [FK_arhRulaje_arhConturi_Credit] FOREIGN KEY ([ContCredit], [CodUnitate], [An]) REFERENCES [dbo].[arhConturi] ([Cont], [CodUnitate], [An]),
    CONSTRAINT [FK_arhRulaje_arhConturi_Debit] FOREIGN KEY ([ContDebit], [CodUnitate], [An]) REFERENCES [dbo].[arhConturi] ([Cont], [CodUnitate], [An]),
    CONSTRAINT [FK_arhRulaje_arhRulajeDoc] FOREIGN KEY ([IDDocument]) REFERENCES [dbo].[arhRulajeDoc] ([IDDocument]),
    CONSTRAINT [FK_arhRulaje_Unitati] FOREIGN KEY ([CodUnitate]) REFERENCES [dbo].[Unitati] ([CodUnitate]),
    CONSTRAINT [FK_arhRulaje_Valuta] FOREIGN KEY ([CodValuta]) REFERENCES [dbo].[Valuta] ([CodValuta])
);

